<template>
    <view
        @tap="__e"
        @touchmove.stop.prevent="__e"
        class="mask data-v-7c9d0d86"
        :data-event-opts="[
            ['tap', [['cancel', ['$event']]]],
            ['touchmove', [['', ['$event']]]]
        ]"
    >
        <view @tap.stop.prevent="__e" class="mask-content data-v-7c9d0d86" :data-event-opts="[['tap', [['', ['$event']]]]]">
            <text @tap="__e" class="new-iconfont icon-close close-btn data-v-7c9d0d86" :data-event-opts="[['tap', [['cancel', ['$event']]]]]"></text>
            <view class="title data-v-7c9d0d86">购买VIP会员套餐</view>
            <view class="item-title data-v-7c9d0d86">选择套餐:</view>
            <view class="sku-list data-v-7c9d0d86">
                <view
                    @tap="__e"
                    :class="['item', 'data-v-7c9d0d86', item.id === skuId ? 'actived' : '']"
                    :data-event-opts="[['tap', [['selectSku', ['$0'], [[['skuList', '', index]]]]]]]"
                    v-for="(item, index) in skuList"
                    :key="index"
                >
                    {{ item.title }}
                </view>
            </view>
            <view class="flex-block data-v-7c9d0d86">
                <view class="item-title data-v-7c9d0d86">可用优惠券:</view>
                <view @tap="__e" class="arrow-right bold data-v-7c9d0d86" :data-event-opts="[['tap', [['e0', ['$event']]]]]">
                    <text class="meta data-v-7c9d0d86" v-if="order.coupon_discount">{{ '- ¥' + $root.g0 }}</text>
                    <block v-else>
                        <text class="meta data-v-7c9d0d86" style="color: #ff1a1a" v-if="$root.g1">{{ $root.g2 + '张可用' }}</text>
                        <text class="meta gray-text data-v-7c9d0d86" v-else>暂无可用优惠券</text>
                    </block>
                    <text class="new-iconfont icon-arrow-right data-v-7c9d0d86"></text>
                </view>
            </view>
            <view class="item-title data-v-7c9d0d86">收货地址:</view>
            <select-address
                @__l="__l($event, { eventOpts: [['^input', [['__set_model', ['', 'address', '$event', []]]]]] })"
                @input="__e($event, { eventOpts: [['^input', [['__set_model', ['', 'address', '$event', []]]]]] })"
                class="data-v-7c9d0d86"
                :data-event-opts="[['^input', [['__set_model', ['', 'address', '$event', []]]]]]"
                :value="address"
                vueId="508b5958-1"
            ></select-address>
            <view class="total data-v-7c9d0d86">
                小计：
                <price-display @__l="__l" class="data-v-7c9d0d86" :info="order" prefix="pay_" vueId="508b5958-2"></price-display>
            </view>
            <view @tap="__e" class="button data-v-7c9d0d86" :data-event-opts="[['tap', [['submit', ['$event']]]]]">
                <text class="data-v-7c9d0d86">确认购买</text>
            </view>
        </view>
        <usable-coupon-popup
            @__l="
                __l($event, {
                    eventOpts: [
                        ['^change', [['couponChange']]],
                        ['^close', [['e1']]]
                    ]
                })
            "
            @change="
                __e($event, {
                    eventOpts: [
                        ['^change', [['couponChange']]],
                        ['^close', [['e1']]]
                    ]
                })
            "
            @close="
                __e($event, {
                    eventOpts: [
                        ['^change', [['couponChange']]],
                        ['^close', [['e1']]]
                    ]
                })
            "
            class="data-v-7c9d0d86"
            :data-event-opts="[
                ['^change', [['couponChange']]],
                ['^close', [['e1']]]
            ]"
            :unusableCoupons="unusableCoupons"
            :usableCoupons="usableCoupons"
            vueId="508b5958-3"
            v-if="isCouponPopup"
        ></usable-coupon-popup>
    </view>
</template>

<script>
import selectAddress from '@/components/SelectAddress/SelectAddress';
import priceDisplay from '@/components/PriceDisplay/PriceDisplay';
import usableCouponPopup from '@/components/UsableCouponPopup/UsableCouponPopup';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/buyVip/components/PayCard'],
    {
        1009: function (n, e, t) {
            'use strict';

            t.d(e, 'b', function () {
                return u;
            });
            t.d(e, 'c', function () {
                return s;
            });
            t.d(e, 'a', function () {
                return o;
            });
            var o = {
                SelectAddress: function () {
                    return t.e('components/SelectAddress/SelectAddress').then(t.bind(null, '8a38'));
                },
                PriceDisplay: function () {
                    return t.e('components/PriceDisplay/PriceDisplay').then(t.bind(null, '6b05'));
                },
                UsableCouponPopup: function () {
                    return t.e('components/UsableCouponPopup/UsableCouponPopup').then(t.bind(null, '3858'));
                }
            };
            var u = function () {
                var that = this;
                var e = (that.$createElement, that._self._c, that.order.coupon_discount ? that.$tool.formatPrice(that.order.coupon_discount) : null);
                if (that.order.coupon_discount) {
                    var t = null;
                } else {
                    var t = that.usableCoupons.length;
                }
                if (!that.order.coupon_discount && t) {
                    var o = that.usableCoupons.length;
                } else {
                    var o = null;
                }
                that._isMounted ||
                    ((that.e0 = function (e) {
                        that.isCouponPopup = true;
                    }),
                    (that.e1 = function (e) {
                        that.isCouponPopup = false;
                    }));
                that.$mp.data = Object.assign(
                    {},
                    {
                        $root: {
                            g0: e,
                            g1: t,
                            g2: o
                        }
                    }
                );
            };
            var s = [];
        },
        3131: function (n, e, t) {
            'use strict';

            var o = t('ae66');
            t.n(o).a;
        },
        '6a6c': function (n, e, t) {
            'use strict';

            (function (n) {
                var o = t('4ea4');
                Object.defineProperty(e, '__esModule', {
                    value: true
                });
                e.default = void 0;
                var u = o(t('9523'));
                var s = o(t('82c0'));
                function i(n, e) {
                    var t = Object.keys(n);
                    if (Object.getOwnPropertySymbols) {
                        var o = Object.getOwnPropertySymbols(n);
                        if (e) {
                            o = o.filter(function (e) {
                                return Object.getOwnPropertyDescriptor(n, e).enumerable;
                            });
                        }
                        t.push.apply(t, o);
                    }
                    return t;
                }
                function r(n) {
                    for (var e = 1; e < arguments.length; e++) {
                        var t = null != arguments[e] ? arguments[e] : {};
                        e % 2
                            ? i(Object(t), true).forEach(function (e) {
                                  (0, u.default)(n, e, t[e]);
                              })
                            : Object.getOwnPropertyDescriptors
                            ? Object.defineProperties(n, Object.getOwnPropertyDescriptors(t))
                            : i(Object(t)).forEach(function (e) {
                                  Object.defineProperty(n, e, Object.getOwnPropertyDescriptor(t, e));
                              });
                    }
                    return n;
                }
                var c = {
                    components: {},
                    data: function () {
                        return {
                            skuList: [],
                            skuId: 0,
                            address: {},
                            order: {},
                            unusableCoupons: [],
                            usableCoupons: [],
                            selectedSku: {},
                            isCouponPopup: false,
                            currentCoupon: {}
                        };
                    },
                    props: {},
                    computed: {},
                    watch: {
                        skuId: function () {
                            this.initOrder();
                        }
                    },
                    onLoad: function (n) {},
                    created: function () {
                        var that = this;
                        n.showLoading();
                        this.$http('/vip-skus').then(function (t) {
                            that.skuList = t.data.list;
                            n.hideLoading();
                            if (that.skuList.length > 0) {
                                that.selectSku(that.skuList[0]);
                            }
                        });
                    },
                    methods: {
                        couponChange: function (n) {
                            n.id === this.currentCoupon.id || ((this.currentCoupon = n), this.initOrder());
                        },
                        selectSku: function (n) {
                            this.skuId = n.id;
                            this.selectedSku = n;
                        },
                        cancel: function () {
                            this.$emit('cancel');
                        },
                        initOrder: function () {
                            var that = this;
                            n.showLoading();
                            this.$http('/vip-order/preview', 'POST', {
                                sku_id: this.skuId,
                                address_id: this.address.id,
                                coupon_id: this.currentCoupon.id
                            }).then(function (t) {
                                that.order = t.data.order;
                                that.unusableCoupons = t.data.order.coupons.unusable;
                                that.usableCoupons = t.data.order.coupons.usable;
                                n.hideLoading();
                            });
                        },
                        submit: function () {
                            var that = this;
                            return this.skuId
                                ? this.address.id
                                    ? (n.showLoading({
                                          title: '提交中',
                                          icon: 'none'
                                      }),
                                      void this.$http('/vip-orders', 'POST', {
                                          sku_id: this.skuId,
                                          address_id: this.address.id,
                                          coupon_id: this.currentCoupon.id
                                      }).then(function (t) {
                                          n.hideLoading();
                                          var o = t.data;
                                          o.is_need_pay
                                              ? s.default.pay(
                                                    r(
                                                        r({}, o),
                                                        {},
                                                        {
                                                            success: function () {
                                                                that.$emit('success');
                                                            },
                                                            fail: function () {
                                                                n.showToast({
                                                                    title: '支付失败',
                                                                    icon: 'none'
                                                                });
                                                                that.$http('/orders/'.concat(o.order.uuid), 'PUT', {
                                                                    type: 'close'
                                                                });
                                                            }
                                                        }
                                                    )
                                                )
                                              : that.$emit('success');
                                      }))
                                    : (n.showModal({
                                          title: '请选择收货地址'
                                      }),
                                      false)
                                : (n.showModal({
                                      title: '请选择套餐'
                                  }),
                                  false);
                        }
                    },
                    onPageScroll: function (n) {}
                };
                e.default = c;
            }.call(this, t('543d').default));
        },
        ae66: function (n, e, t) {},
        ef0d: function (n, e, t) {
            'use strict';

            t.r(e);
            var o = t('1009');
            var u = t('fba8');
            for (var s in u) {
                if (['default'].indexOf(s) < 0) {
                    (function (n) {
                        t.d(e, n, function () {
                            return u[n];
                        });
                    })(s);
                }
            }
            t('3131');
            var i = t('f0c5');
            var r = Object(i.a)(u.default, o.b, o.c, false, null, '7c9d0d86', null, false, o.a, void 0);
            e.default = r.exports;
        },
        fba8: function (n, e, t) {
            'use strict';

            t.r(e);
            var o = t('6a6c');
            var u = t.n(o);
            for (var s in o) {
                if (['default'].indexOf(s) < 0) {
                    (function (n) {
                        t.d(e, n, function () {
                            return o[n];
                        });
                    })(s);
                }
            }
            e.default = u.a;
        }
    }
]);
(global.webpackJsonp = global.webpackJsonp || []).push([
    'pages/buyVip/components/PayCard-create-component',
    {
        'pages/buyVip/components/PayCard-create-component': function (n, e, t) {
            t('543d').createComponent(t('ef0d'));
        }
    },
    [['pages/buyVip/components/PayCard-create-component']]
]);
</script>
<style>
@import './PayCard.css';
</style>
